<?php


namespace App\Http\Services\MeiTuan;


class ResponseHandler
{
    public $send_status = false;
    public $operation_status = false;
    public $msg = '';
    public $trace_id = '';
    public $data = '';//obj

    /**
     * ResponseHandler constructor.
     * @param $response
     */
    public function __construct($response)
    {
        if ($response){
            if ($response->getStatusCode() == 200){
                $this->send_status = true;
            }
            $body = $response->getBody();
            if ($body){
                $this->data = json_decode($response->getBody());
            }
            $this->parseData();
        }

    }

    protected function parseData(){
        if (isset($this->data->code) && $this->data->code == 'OP_SUCCESS'){
            $this->operation_status = true;
        } else {
            if (isset($this->data->code)){
                \Log::notice('ResponseHandler:isset($this->data->code)');
                \Log::notice('ResponseHandler:$this->data->code=>'.$this->data->code);
            } else {
                \Log::notice('ResponseHandler:!isset($this->data->code)');
            }
        }
        if (isset($this->data->msg)){
            $this->msg = $this->data->msg;
        }
        if (isset($this->data->traceId)){
            $this->trace_id = $this->data->traceId;
        }

    }

}
